//
//  CombinationBusinessDetailCell.m
//  HAODE
//
//  Created by LiYinDi on 16/1/21.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "CombinationBusinessDetailCell.h"

@implementation CombinationBusinessDetailCell

- (void)awakeFromNib {
    _outsideAddBtn.layer.borderColor=[[UIColor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:240.0f/255.0f alpha:1.0] CGColor];
    _outsideAddBtn.layer.borderWidth=1.0f;
    _outsideAddBtn.layer.cornerRadius=3.0f;
    _outsideAddBtn.layer.masksToBounds=YES;
    
    _countView.layer.borderColor=[[UIColor colorWithRed:240.0f/255.0f green:240.0f/255.0f blue:240.0f/255.0f alpha:1.0] CGColor];
    _countView.layer.borderWidth=1.0f;
    _countView.layer.cornerRadius=3.0f;
    _countView.layer.masksToBounds=YES;
    
    [self setAutoLayout];

}
- (IBAction)addButtonClick:(UIButton *)sender {
    //    _countLabel.text=[NSString stringWithFormat:@"%d",_countLabel.text.intValue+1];
    if ([self.delegate respondsToSelector:@selector(CellAddBtnClick:)]) {
        
        [self.delegate CellAddBtnClick:sender.tag];
    }
    
}
- (IBAction)subtractButtonClick:(UIButton *)sender {
    //    if (_countLabel.text.intValue>1) {
    //        _countLabel.text=[NSString stringWithFormat:@"%d",_countLabel.text.intValue-1];
    //    }
    if ([self.delegate respondsToSelector:@selector(CellSubtractBtnClick:)]) {
        
        [self.delegate CellSubtractBtnClick:sender.tag];
    }
    
}
- (IBAction)outsideAddBtnClick:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(CellOutsideAddBtnClick:)]) {
        
        [self.delegate CellOutsideAddBtnClick:sender.tag];
    }
    
}

-(void)setAutoLayout
{
    [_productImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@70);
        make.height.equalTo(@70);
        make.left.equalTo(self.mas_left).with.offset(5);
        make.top.equalTo(self.mas_left).with.offset(20);
    }];
    [_productNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_productImageView.mas_right).with.offset(5);
        make.right.equalTo(self.mas_right).with.offset(5);
        make.height.equalTo(@18);
        
        make.top.equalTo(self.mas_left).with.offset(20);
    }];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_productImageView.mas_right).with.offset(5);
        make.right.equalTo(self.mas_right).with.offset(5);
        make.height.equalTo(@18);
        
        make.top.equalTo(_productNameLabel.mas_bottom).with.offset(2);
    }];
    if ( [UIScreen mainScreen].bounds.size.height <667) {
        [_outsideAddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            //        make.left.equalTo(_productImageView.mas_right).with.offset(5);
            make.right.equalTo(self.mas_right).with.offset(-8);
            make.height.equalTo(@25);
            make.width.equalTo(@25);
            make.bottom.equalTo(_productImageView.mas_bottom);
        }];
        
        [_countView mas_makeConstraints:^(MASConstraintMaker *make) {
            //        make.left.equalTo(_productImageView.mas_right).with.offset(5);
            make.right.equalTo(self.mas_right).with.offset(-8);
            make.height.equalTo(@25);
            make.width.equalTo(@75);
            make.bottom.equalTo(_productImageView.mas_bottom);
        }];
        [_subtractButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_countView.mas_left) ;
            make.width.equalTo(@25);
            make.height.equalTo(@25);
            
            make.centerY.equalTo(_countView.mas_centerY);
        }];
        [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_subtractButton.mas_right) ;
            make.width.equalTo(@25);
            make.height.equalTo(@25);
            
            make.centerY.equalTo(_countView.mas_centerY);
        }];
        [_addButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_countLabel.mas_right) ;
            make.width.equalTo(@25);
            make.height.equalTo(@25);
            
            make.centerY.equalTo(_countView.mas_centerY);
        }];
        
    }
    else
    {
        [_countView mas_makeConstraints:^(MASConstraintMaker *make) {
            //        make.left.equalTo(_productImageView.mas_right).with.offset(5);
            make.right.equalTo(self.mas_right).with.offset(-10);
            make.height.equalTo(@30);
            make.width.equalTo(@90);
            make.bottom.equalTo(_productImageView.mas_bottom);
        }];
        [_outsideAddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            //        make.left.equalTo(_productImageView.mas_right).with.offset(5);
            make.right.equalTo(self.mas_right).with.offset(-10);
            make.height.equalTo(@30);
            make.width.equalTo(@30);
            make.bottom.equalTo(_productImageView.mas_bottom);
        }];
        
        
    }
    
    
    
    [_saleCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_productImageView.mas_right).with.offset(5);
        make.right.equalTo(_countView.mas_left);
        make.height.equalTo(@30);
        make.bottom.equalTo(_productImageView.mas_bottom);
        //make.centerY.equalTo(_outsideAddBtn.mas_centerY);
    }];
    
    [_lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(5);
        make.right.equalTo(self.mas_right).with.offset(-5);
        make.height.equalTo(@1);
        make.bottom.equalTo(self.mas_bottom);
        //make.centerY.equalTo(_outsideAddBtn.mas_centerY);
    }];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
